package com.nd.android.u.ui.business4starapp;

import java.io.File;

import com.nd.android.u.business.com.AbstractUploadDownload;
import com.nd.android.u.chatInterfaceImpl.ChatInterfaceImpl;
import com.nd.android.u.controller.innerInterface.IShareFile;
import com.nd.android.u.controller.innerInterface.IShareFileDataSupplier;
import com.nd.android.u.ui.business4starapp.FileCom.FileUploadEntity;

/**
 * 
 * 聊天文件上传类 <br>
 * Created 2014-9-1 上午10:10:34
 * 
 * @version
 * @author youy
 * 
 * @see
 */
public class ShareFileUpload_File extends AbstractUploadDownload {
    @Override
    public void doRequest(IShareFileDataSupplier operation, int type) {
        this.operation = operation;
        this.type = type;
        switch (type) {
        case IShareFile.REPOST:
            doTransKey(operation, type);
            break;
        default:
        	doUpload(operation, type);
            break;
        }

    }

    /**
     * 上传资源 <br>
     * Created 2014-7-28 下午8:11:45
     * 
     * @param operation
     *            操作接口
     * @param type
     *            操作类型
     * @author cb
     */
    private void doUpload(IShareFileDataSupplier operation, int type) {
        FileCom fileComNew = new FileCom(ChatInterfaceImpl.INSTANCE.chatCallOtherModel.getSid());
        fileComNew.setOnUploadListener(uploadListener);
        FileUploadEntity uploadEntity = new FileUploadEntity();
        uploadEntity.sid = ChatInterfaceImpl.INSTANCE.chatCallOtherModel.getSid();
        uploadEntity.file = new File(operation.getResource(type));
        uploadEntity.errMsg = new StringBuilder();
        fileComNew.doUpload(uploadEntity);
    }

    /**
     * 换fkey <br>
     * Created 2014-7-28 下午8:12:05
     * 
     * @param operation
     *            操作接口
     * @param type
     *            操作类型
     * @author cb
     */
    private void doTransKey(IShareFileDataSupplier operation, int type) {
        String key = operation.getResource(type);
        FileCom fileComNew = new FileCom(ChatInterfaceImpl.INSTANCE.chatCallOtherModel.getSid());
        fileComNew.setOnUploadListener(uploadListener);
        fileComNew.transmitFile(key, new StringBuilder());
    }
}
